﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

<style>
    .pagination > li > a, .pagination > li > span {
    cursor: pointer;
}
</style>
<script src="~/Content/js/bootstrap-paginator.js"></script>
 <!--页面主要内容-->
<main class="lyear-layout-content">

    <div class="container-fluid">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-toolbar clearfix">                     
                        <div class="toolbar-btn-action">
                            <a class="btn btn-primary m-r-5" href="#!" onclick="AddMatch()"><i class="mdi mdi-plus"></i> 新增</a>
                            @*<a class="btn btn-success m-r-5" href="#!"><i class="mdi mdi-check"></i> 启用</a>
        <a class="btn btn-warning m-r-5" href="#!"><i class="mdi mdi-block-helper"></i> 禁用</a>*@
                            <a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 删除</a>
                            <div class="col-lg-6">
                                <div class="input-group">
                                    <input type="text" class="form-control" id="keyword" name="keyword" placeholder="请输入关键词...">
                                    <span class="input-group-btn">
                                        <button class="btn btn-default" type="button" onclick="search()">搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">

                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>
                                            <label class="lyear-checkbox checkbox-primary">
                                                <input type="checkbox" id="check-all"><span></span>
                                            </label>
                                        </th>
                                        <th>编号</th>
                                        <th>比赛名</th>
                                        @*<th>比赛地点</th>*@
                                        <th>赛季</th>
                                        <th>开始时间</th>
                                        <th>结束时间</th>
                                        @*<th>是否进入决赛</th>*@
                                        <th>创建时间</th>                                        
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="matchtbody">
                                   
                                
                                </tbody>
                            </table>
                        </div>
                        <ul class="pagination" id="page">
                           
                        </ul>

                    </div>
                </div>
            </div>

        </div>

    </div>

</main>
<!--End 页面主要内容-->
<script>

    $(function () {
        $("#Admin").addClass("active").siblings().removeClass("active");
        $("#Amatch").addClass("active").siblings().removeClass("active");
        getPageOfData(1);  //初始化页面

    })
    function getPageOfData(page) {

        var pageSize = 10;
        var keyword = $("#keyword").val();

        $.ajax({
            url: "/Admin/GetMatch", //你的接口
            data: {
                pageIndex: page,  //页数
                pageSize: pageSize,  //每页几条
                keyword: keyword,
                
            },
            dataType: "json",
            //async: false,
            success: function (data) {
                var result = data.dt.length;
                var dt = data.dt;
                var strHtml = "";
                for (var i = 0; i < dt.length; i++) {
                    var temp = dt[i];
                    strHtml = strHtml + '<tr><td><label class="lyear-checkbox checkbox-primary"><input type="checkbox" name="ids[]" value="' + temp.ID + '"><span></span></label></td>';
                    strHtml = strHtml + '<td>'+temp.ID+'</td>';
                    strHtml = strHtml + '<td>' + temp.MatchName + '</td>';
                    //strHtml = strHtml + '<td>' + temp.MatchArea + '</td>';
                    strHtml = strHtml + '<td>' + temp.MatchQuarter + '</td>';
                    strHtml = strHtml + '<td>' + temp.MatchTimeBegin1 + '</td>';
                    strHtml = strHtml + '<td>' + temp.MatchTimeEnd1 + '</td>';
                    //strHtml = strHtml + '<td>' + temp.IsFinalMatch + '</td>';
                    strHtml = strHtml + '<td>' + temp.CreateTime1 + '</td>';
                    strHtml = strHtml + '<td>';
                    strHtml = strHtml + '<div class="btn-group"><a class="btn btn-xs btn-default edit"  val="' + temp.ID + '" href="#!" title="编辑" data-toggle="tooltip" ><i class="mdi mdi-pencil"></i></a>';
                    strHtml = strHtml + '<a class="btn btn-xs btn-default" href="#!" title="删除" onclick="del('+ temp.ID +')" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>';
                    strHtml = strHtml + '</div></td></tr>';
                }

                $('#matchtbody').html("");
                $('#matchtbody').html(strHtml);


                var totalPages = data.ToalPage;// Math.ceil(data.records / pageSize); //条数除以页数，是总页数
                var element = $('#page');  //ul的id
                var options = {
                    bootstrapMajorVersion: 3,
                    currentPage: page, // 当前页数
                    //numberOfPages: 5, // 显示按钮的数量
                    totalPages: totalPages, // 总页数
                    itemTexts: function (type, page, current) {
                        switch (type) {
                            case "first":
                                return "首页";
                            case "prev":
                                return "上一页";
                            case "next":
                                return "下一页";
                            case "last":
                                return "末页";
                            case "page":
                                return page;
                        }
                    },
                    // 点击事件，用于通过Ajax来刷新整个list列表
                    onPageClicked: function (event, originalEvent, type, page) {
                        getPageOfData(page);
                    }
                };

                element.bootstrapPaginator(options);

                $(".edit").click(function () {
                    var id = $(this).attr("val");
                    window.location.href = "/admin/EditMatch?id="+id;
                })

            }
        }
        );
    };

    function search() {
        getPageOfData(1);
    }
    function AddMatch() {
        window.location.href = "/admin/EditMatch";
    }

    function del(id) {

        $.alert({
            title: '提示框',
            content: '<br> 确定 <strong>删除?</strong>',
            buttons: {
                confirm: {
                    text: '确认',
                    btnClass: 'btn-primary',
                    action: function () {

                        delajax(id);
                    }
                },
                cancel: {
                    text: '取消',
                    action: function () {
                        //$.alert('你点击了取消!');
                    }
                }
            }
        });



    }
    function delajax(id) {
        $.ajax({
            url: "/Admin/del",
            data: { id: id },
            dataType: "json",
            success: function (data) {
                if (data != null) {
                    lightyear.notify('操作成功~', 'success', 2000, 'mdi mdi-emoticon-happy', 'top', 'center');
                    getPageOfData(1);
                }
            }
        })
    }

    function EditMatch(id) {
        window.location.href = "/admin/EditMatch?id="+id;
    }
</script>

